import java.util.Scanner;

// 将一个长度最多为30位数字的十进制整数转换为二进制数输出。
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        boolean flag = true;
        if(m<0) {
            flag = false;
            m = -m;
        }
        StringBuffer stringBuffer = new StringBuffer();
        //小于10进制,一直除n,取余数
        int tem = m;
        if(0 == m) {
            System.out.print(0);
        }else {
            while(tem>0) {
                int num = tem%n;
                if(num>=10) {
                    stringBuffer.append((char)('A'+ (char)(num%10)));
                }else {
                    stringBuffer.append(num);
                }
                tem/=n;
            }
            stringBuffer.reverse();
            if(!flag) {
                System.out.println("-" + stringBuffer);
            }else {
                 System.out.println(stringBuffer);
            }
        }
        
        
    }
}